package com.example.fourthweek;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity  {
    private static final String TAG = "mytest";
    TextView tv;
    EditText editText;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        tv = findViewById(R.id.tv);//在代码中获取控件 此id一定要包含在activity_main中
        tv.setText("结果为：");

       editText = findViewById(R.id.editTextTextPersonName3);
        String s1 = editText.getText().toString();
        Button button = findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String str = editText.getText().toString();
                double result = (int) (Integer.parseInt(str)*1.8 + 32);
                tv.setText("结果为：" + result);
                //Log.i(TAG, "onClick: AAABBB");
            }
        });

        //button.setOnClickListener(this);
       // Log.i(TAG, "onCreate: s1=" +s1);
        // Log.i("class1","this is a msg");//tag 和msg不属于我们的代码内容，而是自带的标签
    }


}